//package cn.sdormitory.mq;
//
//
//import cn.sdormitory.basedata.entity.BStudent;
//import cn.sdormitory.basedata.service.BStudentService;
//import com.alibaba.fastjson.JSON;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.annotation.*;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.Message;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//
///**
// * RabbitMQ消息接收
// */
//@Component
//@Slf4j
//public class RabbitReceiveService {
//    @Autowired
//    private BStudentService bStudentService;
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(value = "consult", durable = "true"),
//            exchange = @Exchange(name = "exchange-1",
//                    durable = "true",
//                    type = "topic",
//                    ignoreDeclarationExceptions = "true"),
//            key = "springboot.rabbit"
//    )
//    )
//    @RabbitHandler
//    public void onMessage(Message message, Channel channel) throws Exception {
//
//        log.info("Rabbit Receive Message:{}",message.getPayload());
//        log.info("Rabbit Receive Header key:{}",message.getHeaders().get("key"));
//        //	spring.rabbitmq.listener.simple.acknowledge-mode=manual
//        String messageStr = String.valueOf(message.getPayload());
//        Map<String,Object> map = JSON.parseObject(messageStr, Map.class);
//        String businessType = (String)map.get("businessType");
//        //直接收指定业务类型的消息
//        if("addStudent".equals(businessType)){
//            //业务处理
//            String data = (String)map.get("data");
//            //BStudent bStudent = JSON.parseObject(data, BStudent.class);
//            //int num = bStudentService.insert(bStudent);
//            //处理成功之后 获取deliveryTag 并进行手工的ACK操作, 因为我们配置文件里配置的是 手工签收
//            //if(num>0){
//                Long deliveryTag = (Long)message.getHeaders().get(AmqpHeaders.DELIVERY_TAG);
//                channel.basicAck(deliveryTag, false);
//            //}
//
//        }
//
//    }
//}
